package com.thon.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thon.dao.system.RolesDao;
import com.thon.dao.system.SystemDicDataDao;
import com.thon.dao.util.Page;
import com.thon.entity.system.Roles;
import com.thon.service.system.RolesService;

@Service
@Transactional
public class RolesServiceImpl implements RolesService {

	@Autowired
	private RolesDao rolesDao;	

	@Autowired
	private SystemDicDataDao systemDicDataDao;	

	@Override
	public Roles read(Integer id) {		
		
	    return rolesDao.get(id);
	}

	@Override
	public String create(Roles roles) {
		String msg = "success";		
		rolesDao.save(roles);
		return msg;
	}
		

	@Override
	public String delete(Integer id) {
		String msg = "success";		
		rolesDao.delete(id);
		return msg;
	}

	@Override
	public String update(Roles roles) {		
		
		String msg = "success";
		if (roles.getRoleType() == null)
			return "rolesType is null";
		roles.setRoleType(systemDicDataDao.get(roles.getRoleType().getId()));
		rolesDao.update(roles);
		return msg;
	}

	@Override
	public List<Roles> readList() {
	
			return rolesDao.readList();
	
	}

	@Override
	public Page<Roles> readListPage(Integer pageNo, Integer pageSize) {
		Page<Roles> page = new Page<Roles>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.desc("sort");
		return rolesDao.readListPage(page);
	}
	


}